﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Text;
using System.Web.Services;

using CE.Database;
using CE.Mail;
using CE.Global;
using CE.CarInsurance;
using CE.User;
using CE.Security;

public partial class car_insurance_your_details : System.Web.UI.Page
{
    protected override void InitializeCulture()
    {
        String selectedCulture = CE.Global.General.SetCulture();
        base.InitializeCulture();
    }

    CE.User.Profile _profile = null;
    CE.User.ProfileDB _profiledb = null;
    Contact _contact = null;
    ContactDB _contactdb = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        HtmlLink css = new HtmlLink();
        css.Href = Resources.CarMenu.CssUrl;
        css.Attributes["rel"] = "stylesheet";
        css.Attributes["type"] = "text/css";
        css.Attributes["media"] = "all";
        Page.Header.Controls.Add(css);

        if (!IsPostBack)
        {
            LoadTitles();
            txtUserName.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtUserName.ClientID + "','" + rfvUserName.ClientID + "','" + revUserName.ClientID + "');DefaultName(this, event);");
            txtUserName.Attributes.Add("onfocus", "ClearText(this, event);");
            txtUserEmail.Attributes.Add("onblur", "RemoveSpace(this);ShowValidationEffectTwo('" + txtUserEmail.ClientID + "','" + rfvUserEmail.ClientID + "','" + revUserEmail.ClientID + "');DefaultEmail(this, event);");
            txtUserEmail.Attributes.Add("onfocus", "ClearText(this, event);");
            txtUserMobile.Attributes.Add("onblur", "RemoveSpace(this);ShowValidationEffectTwo('" + txtUserMobile.ClientID + "','" + rfvUserMobile.ClientID + "','" + revUserMobile.ClientID + "');DefaultPhone(this, event);");
            txtUserMobile.Attributes.Add("onfocus", "ClearText(this, event);");

            if (Request.QueryString["qid"] != null && Request.QueryString["qid"].ToString() != string.Empty)
            {
                hdnQuoteId.Value = Request.QueryString["qid"].ToString();
            }
            if (Request.QueryString["cid"] != null && Request.QueryString["cid"].ToString() != string.Empty)
            {
                hdnCarId.Value = Request.QueryString["cid"].ToString();
            }
            if (Request.QueryString["pid"] != null && Request.QueryString["pid"].ToString() != string.Empty)
            {
                hdnPolicyId.Value = Request.QueryString["pid"].ToString();
            }
            if (Session[CE.Global.General.IsAcceptTC] != null)
            {
                chkAggrement.Checked = true;
                if (Session[CE.Global.General.IsAcceptTC].ToString() != "1")
                {
                    chkAggrement.Checked = false;
                }
            }

            HttpCookie _cookie = Request.Cookies.Get("GGMobileQuote");
            if (_cookie != null)
            {
                GetCookies();
                if (txtUserName.Text.Trim() != string.Empty && txtUserEmail.Text.Trim() != string.Empty && txtUserMobile.Text.Trim() != string.Empty)
                {
                    GetUserDetails(Server.HtmlEncode(txtUserEmail.Text.Trim().ToLower()));
                    #region Hide and add on 10 Feb 2015
                    //if (Session[CE.Global.General.IsAcceptTC] != null)
                    //{
                    //    chkAggrement.Checked = true;
                    //    if (Session[CE.Global.General.IsAcceptTC].ToString() != "1")
                    //    {
                    //        chkAggrement.Checked = false;
                    //    }
                    //}
                    chkAggrement.Checked = true;
                    txtIsAccept.Text = "1";
                    #endregion
                    btnSubmit_Click(null, null);
                }
            }
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            ChangeValidationEffectServerSide("personal");
            Page.Validate("personal");
            if (Page.IsValid)
            {
                Int64 _userId = 0;
                Account _useraccount = new Account();
                AccountDB _useraccountdb = new AccountDB();

                if (hiddenFacebookEmail.Value != "" && (txtUserEmail.Text.Trim().ToLower() == hiddenFacebookEmail.Value.Trim().ToLower()))
                {
                    txtUserEmail.Text = hiddenFacebookEmail.Value;
                }
                else
                {
                    hiddenFacebookID.Value = "";
                }
                _useraccount = _useraccountdb.GetUserAccount(EmailAddress, 400);
                if (_useraccount != null && _useraccount.CEID > 0)
                {
                    _userId = _useraccount.CEID;
                    Profile _userprofile = new Profile();
                    ProfileDB _userprofiledb = new ProfileDB();

                    Contact _usercontact = new Contact();
                    ContactDB _usercontactdb = new ContactDB();

                    Session[CE.Global.General.StartTime] = General.GetUTCDateTime().ToString();
                    _userprofile = _userprofiledb.GetProfile(_useraccount.CEID);

                    if (_userprofile != null && _userprofile.ProfileId > 0)
                    {
                        _userprofile.SurName = string.Empty;
                       // _userprofile.FirstName = Server.HtmlEncode(txtUserName.Text);
                        if (hiddenFacebookID.Value == "")
                        {
                            _userprofile.FirstName = HttpUtility.HtmlEncode(txtUserName.Text);
                        }
                        _userprofile.IsAcceptTC = chkAggrement.Checked;
                        _userprofiledb.Insert(_userprofile);
                    }
                    _usercontact = _usercontactdb.GetContact(_useraccount.CEID);
                    if (_usercontact != null && _usercontact.ContactId > 0)
                    {
                        _usercontact.Mobile = txtUserMobile.Text.Trim();
                        _usercontactdb.Insert(_usercontact);
                    }
                    Session[CE.Global.General.UserId] = _useraccount.CEID;
                    Session[CE.Global.General.UserTypeId] = _useraccount.UserTypeId;
                    Session[CE.Global.General.UserEmail] = _useraccount.Email;
                    Session[CE.Global.General.UserName] = _userprofile.FirstName;
                    Session[CE.Global.General.IsAcceptTC] = "0";
                    if (_userprofile.IsAcceptTC == true)
                    {
                        Session[CE.Global.General.IsAcceptTC] = "1";
                    }
                    Session[CE.Global.General.UserPhoneNo] = _usercontact.Mobile;
                    _useraccount = null;
                    _useraccountdb = null;
                    _userprofile = null;
                    _userprofiledb = null;
                    _usercontact = null;
                    _usercontactdb = null;
                }
                else
                {
                    if (UpdateProfile(_userId, 0) > 0)
                    {
                        SendMailToUser(EmailAddress, Name, MobileNumber); 

                        Session["CLASSTYPE"] = "1";
                        _userId = Convert.ToInt64(Session[General.UserId].ToString());
                    }
                }

                #region FB Login Details
                //Meng Pan Added on 30 Jan 2015 - Start - Insert Facebook ID
                if (hiddenFacebookEmail.Value != "" && (txtUserEmail.Text.Trim().ToLower() == hiddenFacebookEmail.Value.Trim().ToLower()))
                {
                    txtUserEmail.Text = hiddenFacebookEmail.Value;
                }
                string _strEmail = txtUserEmail.Text.Trim();
                DataTable _dt = new DataTable();
                MyDatabase _db = new MyDatabase();
                string _sqlString = @"SELECT CEID,FacebookID FROM tblCEUser 
                                        WHERE TempEinfo1 = '" + _strEmail + "' And UsrTypeId = 400 And [Status] = 1 ";
                string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.IsCXLive");
                if (_strCXLive == "1")
                {
                    _sqlString = @"OPEN SYMMETRIC KEY CXUserSym DECRYPTION BY CERTIFICATE CXUserCert SELECT CEID,FacebookID FROM tblCEUser 
                                        WHERE CONVERT(VARCHAR(50), DECRYPTBYKEY(EInfo1)) = '" + _strEmail + "' And UsrTypeId = 400 And [Status] = 1 CLOSE SYMMETRIC KEY CXUserSym";
                }
                _dt = _db.GetDataTable(_sqlString);
                _db = null;

                if (_dt != null && _dt.Rows.Count > 0)
                {
                    if (_dt.Rows[0]["FacebookID"].ToString() == "")
                    {
                        try
                        {
                            Int64 _result = -1;
                            _db = new MyDatabase();
                            DataTable _dtResult = new DataTable();
                            string _spName = "sprocUserUpdateSingleItemFacebookID";
                            SortedList _sPara = new SortedList();
                            _sPara.Add("@CEID", Int64.Parse(_dt.Rows[0]["CEID"].ToString()));
                            _sPara.Add("@FacebookID", hiddenFacebookID.Value);

                            _result = _db.ExecuteNonSqlSP(_spName, _sPara);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                //Meng Pan Added on 30 Jan 2015 - End - Insert Facebook ID
                #endregion

                SetCookies();
                if (_userId > 0)
                {
                    Response.Redirect("results.aspx?qid=" + hdnQuoteId.Value + "&cid=" + hdnCarId.Value + "&pid=" + hdnPolicyId.Value);
                }
            }
        }
        catch (Exception ex)
        {
        }
    }

    private void SetCookies()
    {
        try
        {
            string _isAccept = "FALSE";
            if (chkAggrement.Checked == true)
            {
                _isAccept = "TRUE";
            }
            string _strName = HttpUtility.HtmlEncode(txtUserName.Text.Trim());
            if (Session[CE.Global.General.UserName] != null)
            {
                _strName = Session[CE.Global.General.UserName].ToString();
            }

            HttpCookie _cookie = new HttpCookie("GGMobileQuote");
            _cookie.Values.Add("CustomerName", MySecurity.Encrypt(_strName, true));
            //_cookie.Values.Add("CustomerName", MySecurity.Encrypt(txtUserName.Text, true));
            _cookie.Values.Add("CustomerEmail", MySecurity.Encrypt(txtUserEmail.Text, true));
            _cookie.Values.Add("CustomerMobile", MySecurity.Encrypt(txtUserMobile.Text, true));
            _cookie.Values.Add("IsAccept", MySecurity.Encrypt(_isAccept, true));

            _cookie.Expires = DateTime.Now.AddDays(90);
            Response.Cookies.Add(_cookie);
        }
        catch (Exception Ex)
        {
            Ex = null;
        }
    }

    private void GetCookies()
    {
        try
        {
            HttpCookie _cookie = Request.Cookies.Get("GGMobileQuote");
            if (_cookie != null)
            {
                txtUserName.Text = MySecurity.Decrypt(_cookie.Values.Get("CustomerName"), true);
                txtUserEmail.Text = MySecurity.Decrypt(_cookie.Values.Get("CustomerEmail"), true);
                string _mobile = MySecurity.Decrypt(_cookie.Values.Get("CustomerMobile"), true);
                txtUserMobile.Text = _mobile;
               
            }
        }
        catch (Exception Ex)
        {
            Ex = null;
        }
    }

    private Int64 UpdateProfile(Int64 UserId, Int64 CarId)
    {
        Int64 _retValue = 0;

        if (UserId != 0)
        {
            Profile _profile = new Profile();
            ProfileDB _profiledb = new ProfileDB();

            Contact _contact = new Contact();
            ContactDB _contactdb = new ContactDB();

            _profile = _profiledb.GetProfile(UserId);
            _contact = _contactdb.GetContact(UserId);
            _retValue = UserId;
            if (_profile != null)
            {
                #region Update Profile

                _profile.Salutation = "";
                //_profile.FirstName = HttpUtility.HtmlEncode(txtUserName.Text);
                if (hiddenFacebookID.Value == "")
                {
                    _profile.FirstName = HttpUtility.HtmlEncode(txtUserName.Text);
                }
                _profile.SurName = "";
                if (_profile.DOB.Year == 1900)
                {
                    DateTime dteDOB = new DateTime(1995, 1, 1);
                    _profile.DOB = dteDOB;
                }
                if (_profile.Gender.ToString().Trim() == "")
                {
                    _profile.Gender = 'M';
                }
                _profile.Status = "Complete";
                _profile.IsAcceptTC = chkAggrement.Checked;

                _retValue = _profiledb.Insert(_profile);

                if (_retValue > 0 && _contact != null)
                {
                    _contact.Mobile = txtUserMobile.Text.Trim();
                    _contact.Status = true;

                    _retValue = _contactdb.Insert(_contact);
                }

                if (_retValue > 0)
                {
                    if (_profile.FirstName != string.Empty)
                    {
                        Session[CE.Global.General.UserName] = _profile.FirstName + " " + _profile.SurName;
                    }
                    else
                    {
                        Session[CE.Global.General.UserName] = _profile.SurName;
                    }
                    Session[CE.Global.General.IsAcceptTC] = "0";
                    if (_profile.IsAcceptTC == true)
                    {
                        Session[CE.Global.General.IsAcceptTC] = "1";
                    }
                    if (_contact != null)
                    {
                        Session[General.UserPhoneNo] = _contact.Mobile;
                    }
                    Session[CE.Global.General.UserProfileAndContactComplete] = "1";
                }

                _profile = null;
                _contact = null;
                #endregion
            }
        }
        else
        {
            _retValue = SaveNewCustomer();
            UserId = _retValue;
        }
        return _retValue;
    }

    private Int64 SaveNewCustomer()
    {
        #region New Customer
        Int64 _retVal = 0;
        if (Page.IsValid)
        {

            Account _useraccount = new Account();
            AccountDB _useraccountdb = new AccountDB();

            Profile _userprofile = new Profile();
            ProfileDB _userprofiledb = new ProfileDB();

            Contact _contact = new Contact();
            ContactDB _contactdb = new ContactDB();

            _useraccount = _useraccountdb.GetUserAccount(txtUserEmail.Text.Trim(), 400);
            if (_useraccount != null)
            {
                if (_useraccount.CEID > 0)
                {
                    _retVal = _useraccount.CEID;
                    _contact = _contactdb.GetContact(_useraccount.CEID);
                    Session[CE.Global.General.UserId] = _useraccount.CEID;
                    Session[CE.Global.General.UserTypeId] = _useraccount.UserTypeId;
                    Session[CE.Global.General.UserEmail] = _useraccount.Email;
                    Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
                    Session[CE.Global.General.StartTime] = General.GetUTCDateTime().ToString();
                    _userprofile = _userprofiledb.GetProfile(_useraccount.CEID);
                    if (_userprofile != null && _userprofile.ProfileId > 0)
                    {
                        if (_userprofile.FirstName != string.Empty)
                        {
                            Session[CE.Global.General.UserName] = _userprofile.FirstName + " " + _userprofile.SurName;
                        }
                        else
                        {
                            Session[CE.Global.General.UserName] = _userprofile.SurName;
                        }
                    }
                }
            }
            else
            {

                long _result = -1;
                _useraccount = new Account();
                _useraccount.Email = txtUserEmail.Text.Trim().ToLower();
                string _authcode = txtUserMobile.Text.Trim();
                _useraccount.AuthCode = _authcode;
                _useraccount.UserId = "CEUSERAUTOIDMOBILECI";
                _useraccount.UserTypeId = 400;
                _useraccount.IsAcceptTC = false;
                _useraccount.Status = true;
                _useraccount.RefCEUserID = -1;
                _result = _useraccountdb.Insert(_useraccount);
                _useraccount.CEID = _result;
                _retVal = _useraccount.CEID;
                if (_result > 0)
                {
                    _userprofile.Salutation = "";
                    _userprofile.FirstName = Server.HtmlEncode(txtUserName.Text);
                    _userprofile.SurName = "";
                    DateTime dteDOB = new DateTime(1995, 1, 1);
                    _userprofile.DOB = dteDOB;
                    _userprofile.Gender = 'M';

                    _userprofile.Occupation = 140;
                    _userprofile.Status = "Complete";
                    _userprofile.RefCEUserId = _useraccount.CEID;
                    _userprofile.IsAcceptTC = chkAggrement.Checked;
                    _result = _userprofiledb.Insert(_userprofile);

                    _contact.Email = _useraccount.Email;
                    _contact.Mobile = txtUserMobile.Text.Trim();

                    _contact.Status = true;
                    _contact.RefCEUserId = _useraccount.CEID;
                    _result = _contactdb.Insert(_contact);

                    if (_result > 0)
                    {
                        Session[CE.Global.General.UserId] = _useraccount.CEID;
                        Session[CE.Global.General.UserTypeId] = _useraccount.UserTypeId;
                        Session[CE.Global.General.UserEmail] = _useraccount.Email;
                        Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
                        Session[CE.Global.General.StartTime] = General.GetUTCDateTime().ToString();
                        if (_userprofile.FirstName != string.Empty)
                        {
                            Session[CE.Global.General.UserName] = _userprofile.FirstName + " " + _userprofile.SurName;
                        }
                        else
                        {
                            Session[CE.Global.General.UserName] = _userprofile.SurName;
                        }
                        Session[CE.Global.General.UserProfileAndContactComplete] = "1";
                        Session[CE.Global.General.IsAcceptTC] = "0";
                        if (_userprofile.IsAcceptTC == true)
                        {
                            Session[CE.Global.General.IsAcceptTC] = "1";
                        }
                    }

                }

            }
        }
        else
        {
            _retVal = 0;
        }

        return _retVal;
        #endregion
    }

    #region Old Methods
    private Int64 SaveNewCustomer_Old()
    {
        #region New Customer
        Int64 _retVal = 0;
        bool _isEmailExist = false;

        Account _useraccount = new Account();
        AccountDB _useraccountdb = new AccountDB();

        Profile _userprofile = new Profile();
        ProfileDB _userprofiledb = new ProfileDB();
        Contact _contact = new Contact();
        ContactDB _contactdb = new ContactDB();

        if (_useraccountdb.IsAlreadyExist(txtUserEmail.Text.Trim(), Convert.ToInt32(CE.Global.General.CEUserType.Customer)))
        {
            _isEmailExist = true;

            _useraccount = _useraccountdb.GetUserAccount(txtUserEmail.Text.Trim(), 400);

            if (_useraccount != null && _useraccount.CEID > 0)
            {
                _contact = _contactdb.GetContact(_useraccount.CEID);
                //if (_contact.Mobile == txtUserMobile.Text.Trim())
                //{
                UpdateProfile(_useraccount.CEID, 0);

                //_profile = _profiledb.GetProfile(_useraccount.CEID);
                Session[CE.Global.General.UserId] = _useraccount.CEID;
                Session[CE.Global.General.UserTypeId] = _useraccount.UserTypeId;
                Session[CE.Global.General.UserEmail] = _useraccount.Email;
                Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
                Session[CE.Global.General.StartTime] = General.GetUTCDateTime().ToString();
                _userprofile = _userprofiledb.GetProfile(_useraccount.CEID);
                if (_userprofile != null && _userprofile.ProfileId > 0)
                {
                    if (_userprofile.FirstName != string.Empty)
                    {
                        Session[CE.Global.General.UserName] = _userprofile.FirstName + " " + _userprofile.SurName;
                    }
                    else
                    {
                        Session[CE.Global.General.UserName] = _userprofile.SurName;
                    }
                }
                _retVal = _useraccount.CEID;
                //}
                //else
                //{
                //    _retVal = 0;
                //}
            }
            else
            {
                _retVal = 0;
            }
        }

        if (_retVal == 0 && _isEmailExist == false)
        {
            long _result = -1;
            _useraccount.Email = txtUserEmail.Text.ToLower();

            string _authcode = txtUserMobile.Text;
            _useraccount.AuthCode = _authcode;

            _useraccount.UserId = "CEUSERAUTOIDMOBILECI";
            _useraccount.UserTypeId = Convert.ToInt32(CE.Global.General.CEUserType.Customer);
            _useraccount.IsAcceptTC = false;
            _useraccount.Status = true;
            _useraccount.RefCEUserID = -1;

            _result = _useraccountdb.Insert(_useraccount);
            _useraccount.CEID = _result;
            _retVal = _useraccount.CEID;

            if (_result > 0)
            {
                _userprofile.Salutation = "";
                _userprofile.FirstName = Server.HtmlEncode(txtUserName.Text);
                _userprofile.SurName = "";

                DateTime _dtDOB = new DateTime(1900, 1, 1);
                _userprofile.DOB = _dtDOB;

                _userprofile.DOB = General.GetUTCDateTime().AddYears(-25);
                _userprofile.Gender = 'M';

                _userprofile.Occupation = 140;
                _userprofile.Status = "Complete";
                _userprofile.RefCEUserId = _useraccount.CEID;
                _userprofile.IsAcceptTC = chkAggrement.Checked;
                _result = _userprofiledb.Insert(_userprofile);

                _contact.Email = _useraccount.Email;
                _contact.Mobile = txtUserMobile.Text;

                _contact.Status = true;
                _contact.RefCEUserId = _useraccount.CEID;
                _result = _contactdb.Insert(_contact);

                if (_result > 0)
                {
                    Session[CE.Global.General.UserId] = _useraccount.CEID;
                    Session[CE.Global.General.UserTypeId] = _useraccount.UserTypeId;
                    Session[CE.Global.General.UserEmail] = _useraccount.Email;
                    Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
                    Session[CE.Global.General.StartTime] = General.GetUTCDateTime().ToString();
                    if (_userprofile.FirstName != string.Empty)
                    {
                        Session[CE.Global.General.UserName] = _userprofile.FirstName + " " + _userprofile.SurName;
                    }
                    else
                    {
                        Session[CE.Global.General.UserName] = _userprofile.SurName;
                    }

                    Session[CE.Global.General.UserProfileAndContactComplete] = "1";
                    Session[CE.Global.General.IsAcceptTC] = "0";
                    if (_userprofile.IsAcceptTC == true)
                    {
                        Session[CE.Global.General.IsAcceptTC] = "1";
                    }

                    SendMailToUser(_useraccount.Email, Session[CE.Global.General.UserName].ToString(), _contact.Mobile);
                }

            }
        }

        return _retVal;
        #endregion
    }

    private Int64 UpdateProfile_Old(Int64 UserId, Int64 CarId)
    {
        Int64 _retValue = 0;

        if (UserId != 0)
        {
            _profile = new CE.User.Profile();
            _profiledb = new ProfileDB();

            _contact = new Contact();
            _contactdb = new ContactDB();

            _profile = _profiledb.GetProfile(UserId);
            _contact = _contactdb.GetContact(UserId);

            if (_profile != null)
            {
                #region Update Profile

                _profile.Salutation = "";
                _profile.FirstName = txtUserName.Text;
                _profile.SurName = "";
                _profile.DOB = General.GetUTCDateTime().AddYears(-25);
                _profile.Gender = 'M';

                _profile.MaritalStatus = -1;
                _profile.JobNature = "";
                _profile.Occupation = 140;
                _profile.YearDriveSg = 0;
                _profile.Status = "Complete";
                _profile.IsAcceptTC = chkAggrement.Checked;

                _retValue = _profiledb.Insert(_profile);

                if (_retValue > 0 && _contact != null)
                {
                    _contact.Mobile = txtUserMobile.Text;
                    _contact.Status = true;

                    _retValue = _contactdb.Insert(_contact);
                }
                else
                {
                }

                if (_retValue > 0)
                {
                    if (_profile.FirstName != string.Empty)
                    {
                        Session[CE.Global.General.UserName] = _profile.FirstName + " " + _profile.SurName;
                    }
                    else
                    {
                        Session[CE.Global.General.UserName] = _profile.SurName;
                    }
                    Session[General.UserPhoneNo] = txtUserMobile.Text;
                    Session[CE.Global.General.UserProfileAndContactComplete] = "1";
                    Session[CE.Global.General.IsAcceptTC] = "0";
                    if (_profile.IsAcceptTC == true)
                    {
                        Session[CE.Global.General.IsAcceptTC] = "1";
                    }
                }

                _profile = null;
                _contact = null;
                #endregion
            }
        }
        return _retValue;
    }
    #endregion

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        txtUserName.Text = HttpUtility.HtmlEncode(txtUserName.Text.Trim());
        txtUserEmail.Text = HttpUtility.HtmlEncode(txtUserEmail.Text.Trim());
        txtUserMobile.Text = HttpUtility.HtmlEncode(txtUserMobile.Text.Trim());

        #region user
        //Name
        if (rfvUserName.Enabled && rfvUserName.ValidationGroup == strValidationGroup)
        {
            rfvUserName.Validate();
            if (rfvUserName.IsValid == false)
            {
                txtUserName.ControlStyle.CssClass = "text-fields validationError";
            }
            else
            {
                txtUserName.ControlStyle.CssClass = "text-fields";
            }
        }
        else
        {
            txtUserName.ControlStyle.CssClass = "text-fields";
        }

        if (revUserName.Enabled && revUserName.ValidationGroup == strValidationGroup)
        {
            if (rfvUserName.IsValid)
            {
                revUserName.Validate();
                if (revUserName.IsValid == false)
                {
                    txtUserName.ControlStyle.CssClass = "text-fields validationError";
                }
                else
                {
                    txtUserName.ControlStyle.CssClass = "text-fields";
                }
            }
        }
        else
        {
            txtUserName.ControlStyle.CssClass = "text-fields";
        }

        //Email
        if (rfvUserEmail.Enabled && rfvUserEmail.ValidationGroup == strValidationGroup)
        {
            rfvUserEmail.Validate();
            if (rfvUserEmail.IsValid == false)
            {
                txtUserEmail.ControlStyle.CssClass = "text-fields validationError";
            }
            else
            {
                txtUserEmail.ControlStyle.CssClass = "text-fields";
            }
        }
        else
        {
            txtUserEmail.ControlStyle.CssClass = "text-fields";
        }

        if (revUserEmail.Enabled && revUserEmail.ValidationGroup == strValidationGroup)
        {
            if (rfvUserEmail.IsValid)
            {
                revUserEmail.Validate();
                if (revUserEmail.IsValid == false)
                {
                    txtUserEmail.ControlStyle.CssClass = "text-fields validationError";
                }
                else
                {
                    txtUserEmail.ControlStyle.CssClass = "text-fields";
                }
            }
        }
        else
        {
            txtUserEmail.ControlStyle.CssClass = "text-fields";
        }

        //Mobile No
        if (rfvUserMobile.Enabled && rfvUserMobile.ValidationGroup == strValidationGroup)
        {
            rfvUserMobile.Validate();
            if (rfvUserMobile.IsValid == false)
            {
                txtUserMobile.ControlStyle.CssClass = "text-fields validationError";
            }
            else
            {
                txtUserMobile.ControlStyle.CssClass = "text-fields";
            }
        }
        else
        {
            txtUserMobile.ControlStyle.CssClass = "text-fields";
        }

        if (revUserMobile.Enabled && revUserMobile.ValidationGroup == strValidationGroup)
        {
            if (rfvUserMobile.IsValid)
            {
                revUserMobile.Validate();
                if (revUserMobile.IsValid == false)
                {
                    txtUserMobile.ControlStyle.CssClass = "text-fields validationError";
                }
                else
                {
                    txtUserMobile.ControlStyle.CssClass = "text-fields";
                }
            }
        }
        else
        {
            txtUserMobile.ControlStyle.CssClass = "text-fields";
        }
        #endregion
    }

    private bool SendMailToUser(string EmailAddress, string UserName, string AuthCode)
    {
        bool _retVal = false;
        _retVal = CE.Email.Welcome.SendMail(EmailAddress, UserName, AuthCode);
        return _retVal;
    }

    private void LoadTitles()
    {
        btnSubmit.Text = Resources.CarMenu.ViewResultNow;
        lblAggrement.Text = Resources.UserMessage.Aggrement;
        //imgDBDOIC.ImageUrl = Resources.CarMenu.DBDOICUrl;
        imgFB.ImageUrl = Resources.CarMenu.ImgBtnFBUrl;
        lblOR.Text = Resources.CarMenu.OR;
    }

    private string EmailAddress
    {
        get { return txtUserEmail.Text.Trim(); }
    }

    private string MobileNumber
    {
        get { return txtUserMobile.Text.Trim(); }
    }

    private string Name
    {
        get { return txtUserName.Text.Trim(); }
    }

    private void GetUserDetails(string CustomerEmail)
    {
        try
        {
            AccountDB _accountdb = new AccountDB();
            Account _account = _accountdb.GetUserAccount(CustomerEmail.ToLower(), 400);
            if (_account != null)
            {
                Session[CE.Global.General.UserId] = _account.CEID;
                Session[CE.Global.General.UserTypeId] = _account.UserTypeId;
                Session[CE.Global.General.UserEmail] = _account.Email;

                Profile _profile = new Profile();
                ProfileDB _profiledb = new ProfileDB();
                Contact _contact = new Contact();
                ContactDB _contactdb = new ContactDB();

                _contact = _contactdb.GetContact(_account.CEID);
                _profile = _profiledb.GetProfile(_account.CEID);

                if (_contact != null)
                {
                    Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
                }
                else
                {
                    Session[CE.Global.General.UserPhoneNo] = null;
                }
                if (_profile != null)
                {
                    if (_profile.FirstName != null && _profile.FirstName != string.Empty)
                    {
                        Session[CE.Global.General.UserName] = Server.HtmlDecode(_profile.FirstName) + " " + Server.HtmlDecode(_profile.SurName);
                    }
                    else
                    {
                        Session[CE.Global.General.UserName] = Server.HtmlDecode(_profile.SurName);
                    }
                    if (_profile.IsAcceptTC != null)
                    {
                        Session[CE.Global.General.IsAcceptTC] = "0";
                        if (_profile.IsAcceptTC == true)
                        {
                            Session[CE.Global.General.IsAcceptTC] = "1";
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
        }
    }

    protected void lkFacebookLogin_Click(object sender, EventArgs e)
    {
        if (hiddenFacebookID.Value != "")
        {
            txtUserName.Text = hiddenFacebookName.Value;
            txtUserEmail.Text = hiddenFacebookEmail.Value;
            //ViewResultWithFBLogin();
            LinkButton1.Visible = false;
            divFBLogin.Visible = false;
        }
    }

}
